package person.tavion.transaction.produce;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserService {
    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;


    @Transactional
    public String sendForTransaction(String userNo, String jsonString) {
        System.out.println("sendForTransaction方法中，是否开启事务中："+kafkaTemplate.inTransaction());
        kafkaTemplate.send("myUser","key",jsonString);
//        kafkaTemplate.send("myUser",jsonString+1);
//        kafkaTemplate.send("myUser",jsonString+2);

//        throw new RuntimeException();
        return "true";
    }
}
